import * as userService from '../services/userService'
import axios from 'axios'


const {query} = userService

export default {
  namespace : 'user',
  state : {
    modal: {
      visible: false,
      type: 'add',
      item: {}
    }
  },
  reducers : {
    showModal(state, {payload}) {

      console.log(state);

      return {
        ...state,
        modal: {
          ...payload,
          visible: true
        }
      };
      //return { ...state, ...payload ,modalVisible: true }
    },
    hideModal(state) {
      return {
        ...state,
        modal: {
          ...state.modal,
          item:{},
          visible: false
        }
      };
    }
  },
  effects : {
    * add({payload},{call,put}){

      console.log('add');
      console.log(payload);
      const data = yield axios.post('/api/v1/sys/user',payload)
      yield put({type:'hideModal'})
      console.log('data');
      console.log(data);
    },
    * update({payload},{put,call}){
      console.log('upd -------------------- ate');
      // console.log(arg);
      const data = yield axios.post('/api/v1/sys/user/update',payload)
      yield put({type:'hideModal'})
    }
  },
  subscriptions : {}
};
